package com.fin.quant.rpc.bean;

import com.orbitz.consul.Consul;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class ConsulConfig {

    @Value("${spring.consul.host}")
    private String host;
    @Value("${spring.consul.port}")
    private int port;

    @Bean
    public Consul consul() {
        log.info("consul. host={} port={}", host, port);
        Consul consul = Consul.builder()
                .withHostAndPort(com.google.common.net.HostAndPort.fromParts(host, port))
                .build();

        // 注册 Consul NameResolverProvider
        ConsulNameResolverProvider.register(consul);

        return consul;
    }


}
